import 'package:ac/data/ac_user_manager.dart';
import 'package:ac/widget/ac_app_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../common/style.dart';
import 'ac_setting_logic.dart';

class AcSettingPage extends StatelessWidget {
  final logic = Get.find<AcSettingLogic>();
  final state = Get.find<AcSettingLogic>().state;

  AcSettingPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AcAppbar(
        title: "Setting",
      ),
      body: Container(
        color: Colors.white,
        width: 375.w,
        padding: EdgeInsets.symmetric(horizontal: 20.w),
        child: Column(
          children: [
            _item(
              "ID : ${AcUserManager.userInfoModel?.userInfo.userId}",
              const SizedBox.shrink(),
              () {},
            ),
            _item(
              "Auto Translate",
              Obx(() {
                return GestureDetector(
                  onTap: logic.setAutoTranslate,
                  child: Container(
                    width: 42.w,
                    height: 22.h,
                    padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 3.w),
                    decoration: BoxDecoration(
                      color: const Color(0xff86FB8C),
                      borderRadius: BorderRadius.circular(15.w),
                    ),
                    child: Row(
                      mainAxisAlignment: !logic.autoTranslate.value
                          ? MainAxisAlignment.start
                          : MainAxisAlignment.end,
                      children: [
                        ClipOval(
                          child: Container(
                            width: 16.w,
                            height: 16.w,
                            color: Colors.white,
                          ),
                        ),
                      ],
                    ),
                  ),
                );
              }),
              () {},
            ),
            _item(
              "Logout",
              Image.asset(
                "images/icon_right.png",
                width: 16.w,
              ),
              logic.logout,
            ),
            _item(
              "Delete account",
              Image.asset(
                "images/icon_right.png",
                width: 16.w,
              ),
              logic.deleteAccount,
            ),
          ],
        ),
      ),
    );
  }

  Widget _item(
    String title,
    Widget right,
    VoidCallback onTap,
  ) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        height: 52.h,
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: const Color(0xffcccccc),
              width: 0.5.w,
            ),
          ),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              title,
              style: TextStyle(
                fontSize: 16.sp,
                color: textColorBlack,
              ),
            ),
            right
          ],
        ),
      ),
    );
  }
}
